{% extends "map/new_base.html" %}

{% comment %}

  Detailed Edit page
  ------------------
  
  This page allows logged in users to edit their markers and add a bit more detail than from the map view.
  
{% endcomment %}

{% block javascript %}
  <script src="http://www.google.com/jsapi"></script>
  <link rel="stylesheet"  href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.0/themes/humanity/jquery-ui.css"  type="text/css" />
  <style type="text/css" rel="stylesheet">
    div.ui-datepicker  {
                         font-size:11px;
                       }
  </style>


   <script type="text/javascript">
      google.load("jquery", "1");
      google.load("jqueryui", "1");  
    </script>


<script src="http://maps.google.com/maps?file=api&amp;v=2.147&amp;key=ABQIAAAAhcP5rdJ8gtI2Tvrvo88B3BR_tirkabJaindNc0FoauOGCOWtrBTLuwigpG4UD6tSDw3AxxYNXLmcVg" type="text/javascript"> </script>
<script type="text/javascript">
mapper = {
  load: function() {
    if (GBrowserIsCompatible()) {
      var default_lat = document.getElementById("id_lat").value;
      var default_lng = document.getElementById("id_lng").value;
      mapper.map = new GMap2(document.getElementById("map"));
      mapper.map.setCenter(new GLatLng(default_lat, default_lng), 15); // should read this out of the form if we can, cos it might be returned if the form is invalid
      mapper.map.setMapType(G_NORMAL_MAP);
      var mapControl = new GMapTypeControl();
      mapper.map.addControl(mapControl);
      mapper.map.addControl(new GLargeMapControl());
      var marker = new GMarker(new GLatLng(default_lat, default_lng),
        {draggable: true, bouncy: true, icon: G_DEFAULT_ICON, title: "New Marker"});
      
      GEvent.addListener(marker, "dragend", function() {
        mapper.map.panTo(this.getLatLng());
        document.getElementById("id_lat").value=this.getLatLng().lat();
        document.getElementById("id_lng").value=this.getLatLng().lng();
      });
      
  mapper.map.addOverlay(marker);
  mapper.map.panTo(marker.getLatLng());
  
  }
 }
}
</script>


<script type="text/javascript">
    $(document).ready(function() {
		$("#id_date_due").datepicker({ dateFormat: 'dd/mm/yy' });
		$("#id_date_ends").datepicker({dateFormat: 'dd/mm/y' });
		$("#freetext").resizable({'maxWidth':'725'});
		$("#descr").resizable({'maxWidth':'725'});
    });
</script>
{% endblock %}

{% block title %}
  Potton Online  |  Edit:  {{marker.name}}
{% endblock %}


{% block bodytag %}
  onload="mapper.load()" onunload="GUnload()"
{% endblock %}

{% block page_middle %}

<form id="fileupload" enctype="multipart/form-data" name="File upload" method="POST" action="./edit" >
  <h1> Edit a map marker </h1>
  <div class="info_area ">
    {{ form.name.errors }}
    <label  {% if form.name.errors %}class="errorlabel"{% endif %} for="id_name">Title:</label><input size="{{marker.name|length|add:"10"}}" type="text" name="name" id="name" value="{{ marker.name }}" title="The name for your entry" />
    <hr />
    {{ form.mtype.errors }}
    <label  {% if form.mtype.errors %}class="errorlabel"{% endif %} for="id_mtype">{{form.mtype.label}}:</label>  {{ form.mtype }}
    <hr />

    {% if marker.owner_user.first_name %}
    <label {% if form.owner_user.errors %}class="errorlabel"{% endif %} >Added by:</label>  {{ marker.owner_user.first_name|capfirst }} {{ marker.owner_user.last_name|capfirst }}
    <hr />
    {% endif %}
    <label>Last updated:</label>  {{marker.lastupdate|date:"D d M Y" }}
    <hr />
    {{form.publicemail.errors}}
    <label {% if form.publicemail.errors %}class="errorlabel"{% endif %} >{{form.publicemail.label}}:</label>{{form.publicemail}}
    <hr />
    {{form.publicphone.errors}}
    <label {% if form.publicphone.errors %}class="errorlabel"{% endif %} >{{form.publicphone.label}}:</label>{{form.publicphone}}
    <hr />
    {{form.link.errors}}
    <label {% if form.link.errors %}class="errorlabel"{% endif %} >{{form.link.label}}:</label>{{form.link}}
    <hr />
    {{form.date_due.errors}}
    <label {% if form.date_due.errors %}class="errorlabel"{% endif %} >{{form.date_due.label}}:</label>{{form.date_due}}
    <hr />
    {{form.date_ends.errors}}
    <label {% if form.date_ends.errors %}class="errorlabel"{% endif %} >{{form.date_ends.label}}:</label>{{form.date_ends}}
  </div>
  
  <div class="info_area  ">
    <label  for="descr">Description</label><textarea id="descr" name="descr" rows="2" cols="50">{{marker.description}}</textarea><hr />
    <label  for="freetext">Additional information:</label>
    <textarea id="freetext" name="freetext" rows="5" cols="60">{% ifnotequal marker.freetext None %} {{marker.freetext}} {% endifnotequal %}</textarea>
  </div>
  
  <div class="info_area ">
    Images:<br/>
    <div style="float: left; width: 30%; height: 220px; padding: 7px; ">
      <img src="{{marker.image1_t|default_if_none:"/assets/graphics/nopicture.png"|default:"/assets/graphics/nopicture.png"}}">
      {{form.file1.errors}}
      {{form.image1}}
    </div>
    <div style="float: left; width: 30%;  height: 220px; padding: 7px;">
      <img src="{{marker.image2_t|default_if_none:"/assets/graphics/nopicture.png"|default:"/assets/graphics/nopicture.png"}}">
      {{form.file2.errors}}
      {{form.image2}}
    </div>
    <div style="float: left; width: 30%;  height: 220px; padding: 7px;">
      <img src="{{marker.image3_t|default_if_none:"/assets/graphics/nopicture.png"|default:"/assets/graphics/nopicture.png"}}">
      {{form.file3.errors}}
      {{form.image3}}
    </div>
    <hr>
  </div>
  
  <div class="info_area ">
    {{form.price.errors}}
    <label {% if form.price.errors %}class="errorlabel"{% endif %} >{{form.price.label}}:</label>{{form.price}}<hr />
    {{form.address.errors}}
    <label  {% if form.address.errors %}class="errorlabel"{% endif %} >{{form.address.label}}:</label>{{form.address}}<hr />
  </div>
  
  <div class="info_area ">
    <div id="map" style="width: 100%; height: 500px;">
    </div>  
    <div style="display: none;">
      {{form.lat}}{{form.lng}}
    </div>
  </div>

  <div class="info_area ">
    {{form.active.errors}}
    <label {% if form.active.errors %}class="errorlabel"{% endif %} >Active:</label> {{form.active}}&nbsp&nbsp(Markers not set as Active will not show up on the map)<br />

{% if marker.premium %}
  <div id="merchant" style="float: left; width: 100%;" >
        Objects associated with this maker:<br />
    {% for mobj in merchant_objects %}
      <div class="merchant_object {% cycle 'mo1' 'mo2' %}" style="width: 45%; padding: 1%; float: left;">
        <a href="{% url merch-edit marker.id mobj.id %}">{{mobj.name}} <br />
        <img src="{{mobj.thumbnail}}"> </a><br />
        {{mobj.description}} <br />
      </div>
      {% if forloop.counter|divisibleby:"2" %} <hr /> {% endif %}
      {% if forloop.last %} <hr /> {% endif %}
    {% endfor %}
  </div>
  <hr />
{% endif %}
    


{% if addmore %} <a href="/merchant/add/{{marker.id}}">Click here to add a new object</a>  {% endif%}

  </div>
  <div class="info_area ">
    <input style="display: inline;" type="submit" value="Submit these changes">&nbsp&nbsp  |  &nbsp&nbsp<a href="/{{marker.slug}}">Cancel these changes</a>
    &nbsp&nbsp  |  &nbsp&nbsp<a href="/{{marker.slug}}">Go back to the Details page</a>
    
  </div>
</form>


{% endblock %}

{% block page_left %}
  {% include 'map/default_pageleft.html' %}
{% endblock %}

{% block page_right %}
  {% include 'map/default_pageright.html' %}
{% endblock %}

